package com.zx.map.service.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zx.map.dao.mapper.MessageInfoMapper;
import com.zx.map.dao.model.MessageInfo;
import com.zx.map.dao.model.MessageInfoExample;
import com.zx.map.service.MessageInfoService;

@Component("messageInfoService")
public class MessageInfoServiceImpl implements MessageInfoService {

	@Autowired
	private MessageInfoMapper mapper;
	
	@Override
	public void sendMessage(MessageInfo messageInfo) {
		mapper.insertSelective(messageInfo);
	}

	@Override
	public PageInfo<MessageInfo> msgList(String merchantId, int pageNum, int pageSize) {
		MessageInfoExample example = new MessageInfoExample();
		MessageInfoExample.Criteria criteria = example.createCriteria();
		if(StringUtils.isNotBlank(merchantId)) {
			criteria.andMerchantIdEqualTo(merchantId);
		}
		example.setOrderByClause("create_datetime desc");
		PageHelper.startPage(pageNum, pageSize);
		List<MessageInfo> list = mapper.selectByExampleWithBLOBs(example);
		PageInfo<MessageInfo> pageInfo = new PageInfo<MessageInfo>(list);
	
		return pageInfo;
	}

}
